package com.peaker.advertisingpro.view

import android.app.Dialog
import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.view.Window
import com.peaker.advertisingpro.R
import com.peaker.advertisingpro.utils.Common
import com.peaker.advertisingpro.utils.SPUtil
import kotlinx.android.synthetic.main.layout_pwd_dialog.*

/**
 *  @ 作者 CODE_LYF
 *  @ 时间   2021/3/18.
 *  代码人生
 */
class PwdDialog(context: Context) : Dialog(context), View.OnClickListener {

    lateinit var onPwdSucced: (type: Int) -> Unit

    init {
        window?.requestFeature(Window.FEATURE_NO_TITLE)
        window?.setBackgroundDrawableResource(R.color.transparent)
        window.setGravity(Gravity.CENTER)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(R.layout.layout_pwd_dialog)
        setCanceledOnTouchOutside(false)
        btn_ok_pwd.setOnClickListener(this)
        btn_cancel_pwd.setOnClickListener(this)


    }

    override fun onClick(v: View?) {
        when (v!!.id) {
            R.id.btn_ok_pwd -> {
                var sp = SPUtil.getSP(Common.PWD)
                if (sp == pwd_et.text.toString()) {
                    if (::onPwdSucced.isInitialized) {
                        onPwdSucced.invoke(0)
                    }
                } else {
                    if (::onPwdSucced.isInitialized) {
                        onPwdSucced.invoke(1)
                    }
                }
                dismiss()
            }
            R.id.btn_cancel_pwd -> {
                if (::onPwdSucced.isInitialized) {
                    onPwdSucced.invoke(1)
                }
                dismiss()
            }
        }
    }

    fun callback() {

    }
}